<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库库位列表')" />
    <th:block th:include="include :: layout-latest-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main" style="height: 100%">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 产品合作区域
            </div>
            <!--<div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="新增一级库位"><i class="fa fa-plus"></i></a>
                <a type="button" class="btn btn-box-tool" href="#" onclick="refreshStore()" title="刷新一级库位"><i class="fa fa-refresh"></i></a>
            </div>-->
        </div>
        <div class="col-sm-12 select-table table-bordered" style="height: 90%">
            <div>
                <form id="formId1">
                   <!-- <input type="hidden" id="areaName" name="areaName">-->
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 120px;color: red">省份名称：</label>
                                <input id="areaName" type="text" name="areaName" style="width: 180px;" placeholder="请输入要查询的名称"/>
                            </li>
                            <li>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.table.search('formId1','bootstrap-table-first')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                <!--<a class="btn btn-warning btn-rounded btn-sm" onclick="addSecond()"><i class="fa fa-plus"></i>&nbsp;新增二级库位名称</a>-->
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <table id="bootstrap-table-first"></table>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div" style="height: 15%">
        <div class="row">
            <div class="btn-group-sm" id="toolbar2" role="group">
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <div>
                    <form id="formId2">
                        <input type="hidden" id="areaNameFirst" name="areaName">
                        <div class="select-list">
                            <ul>
                                <li >
                                    <label style="width: 120px;color: red">城市名称：</label>
                                    <input id="secondAreaName" type="text" name="secondAreaName" placeholder="请输入要查询的名称" />
                                </li>
                                <li>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.table.search('formId2','bootstrap-table-second')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                    <!--<a class="btn btn-warning btn-rounded btn-sm" onclick="addSecond()"><i class="fa fa-plus"></i>&nbsp;新增二级库位名称</a>-->
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <table id="bootstrap-table-second"></table>
            </div>
        </div>
    </div>
    <div class="container-div">
        <div class="row">
            <div class="btn-group-sm" id="toolbar3" role="group">
            </div>
            <div class="col-sm-12 select-table table-bordered" >
                <div>
                    <form id="formId">
                        <input type="hidden" id="areaName2" name="secondAreaName">
                        <input type="hidden" id="areaNameThird" name="areaName">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label style="width: 120px;color: red">市县名称：</label>
                                    <input id="thirdAreaName" type="text" name="thirdAreaName" placeholder="请输入要查询的名称"/>
                                </li>
                                <li>
                                    <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-success btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                    <!--<a class="btn btn-success btn-rounded btn-sm" onclick="addThird()"><i class="fa fa-plus"></i>&nbsp;新增三级库位名称</a>-->
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('warehouse:storehouse:edit')}]];
    var removeFlag = [[${@permission.hasPermi('warehouse:storehouse:remove')}]];
    var typeDatas = [[${@dict.getType('warehouse_type')}]];
    var isDefaultDatas = [[${@dict.getType('sys_yes_no')}]];
    var prefix = ctx + "zsyh/areaAgent";

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 200 });
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win:$('.ui-layout-center'),
                doc:$('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryServiceTypeList();
        queryServiceTypeFirstList();
        queryServiceTypeSecondList();
    });

    function queryServiceTypeFirstList() {
        var options = {
            id: "bootstrap-table-first",
            /*toolbar: "toolbar1",*/
            url: prefix + "/listFirst?areaParentId=0",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: true,
            paginationLoop: true,
            pageSize: 10,
            modalName: "省份",
            queryParams: function (params) {
            var temp ={};
            if(params){
                if (params.areaName) {
                    temp.areaName = params.areaName
                }
            }
            temp.areaName = $("#areaName").val();
            temp.pageSize =10;
            temp.pageNum = params.offset / 10 + 1;
            temp.pageOffset = params.offset;
            return temp;
        },
            columns: [
                {
                    field: 'areaName',
                    align: 'center',
                    title: '省份'
                },
                /*{
                    field: 'deptName',
                    align: 'center',
                    title: '所属组织'
                }*/
                /*{
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }*/
            ],onClickRow:function (row) {
                debugger;
                $("#areaName").val(row.areaName);
                $("#bootstrap-table-second").bootstrapTable('refresh', {query:{
                        areaName: row.areaName
                    }
                });
                $("#areaNameThird").val(row.areaName);
                $("#bootstrap-table").bootstrapTable('refresh', {query:{
                        areaName: row.areaName
                    }
                });
            }

        };
        $.table.init(options);
        /* $.treeTable.init(options);*/
    };

    function queryServiceTypeSecondList() {
        var options = {
            id: "bootstrap-table-second",
            toolbar: "toolbar2",
            url: prefix + "/listSecond",
            createUrl: prefix + "/addSecond/",
            updateUrl: prefix + "/editSecond/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pageSize: 4,
            modalName: "城市名称",
            queryParams: function (params) {
                var temp ={};
                if(params){
                    if (params.areaName) {
                        temp.areaName = params.areaName
                    }
                }
                temp.areaName = $("#areaName").val();
                temp.secondAreaName =$("#secondAreaName").val();
                /*temp.serviceLevel ='2';*/
                temp.pageSize =4;
                temp.pageNum = params.offset / 4 + 1;
                temp.pageOffset = params.offset;
                return temp;
            },
            columns: [{
                field : 'Number',
                title : '序号',
                align: 'center',
                width: 20,
                formatter : function(value, row, index) {
                    var pageSize = $('#bootstrap-table-second').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                    var pageNumber = $('#bootstrap-table-second').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                    return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                }
            },
                {
                    field: 'id',
                    title: 'id',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'areaName',
                    align: 'center',
                    title: '省份'
                },
                {
                    field: 'secondAreaName',
                    align: 'center',
                    title: '城市'
                },
                /*{
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeStore(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }*/],onClickRow:function (row) {
                debugger;
                $("#areaName2").val(row.secondAreaName);
                $("#bootstrap-table").bootstrapTable('refresh', {query:{
                        secondAreaName: row.secondAreaName
                    }
                });
            }
        };
        $.table.init(options);
    };

    function queryServiceTypeList() {
        var options = {
            id: "bootstrap-table",
            toolbar: "toolbar3",
            url: prefix + "/listThird/",
            createUrl: prefix + "/add/",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            exportUrl: prefix + "/export",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pageSize: 8,
            modalName: "市县",
            queryParams: function (params) {
                var temp ={};
                if(params){
                    if (params.areaName) {
                        temp.areaName = params.areaName
                    }
                }
                temp.areaName = $("#areaNameThird").val();
                temp.secondAreaName = $("#areaName2").val();
                temp.thirdAreaName =$("#thirdAreaName").val();
                /*temp.ancestors ='3';*/
                temp.pageSize =8;
                temp.pageNum = params.offset / 8 + 1;
                temp.pageOffset = params.offset;
                return temp;
            },
            columns: [{
                field : 'Number',
                title : '序号',
                align: 'center',
                width: 20,
                formatter : function(value, row, index) {
                    var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                    var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                    return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                }
            },
                {
                    field: 'id',
                    title: 'id',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'areaName',
                    align: 'center',
                    title: '省份'
                },
                {
                    field: 'secondAreaName',
                    align: 'center',
                    title: '城市'
                },
                {
                    field: 'thirdAreaName',
                    align: 'center',
                    title: '市县'
                },
                {
                    field: 'peopleNum',
                    align: 'center',
                    title: '人口数量(万)'
                },
                /*{
                    field: 'parentId',
                    title: '服务类型父Id'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        /*actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeStore(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    };

    function addSecond() {
        $.modal.open("添加二级库位名称", prefix + "/addNext");
    }

    function addThird() {
        $.modal.open("添加三级库位名称", prefix + "/addThird");
    }

    /*function dept() {
        var url = ctx + "warehouse/storehouse/storehouseDetail";
        $.modal.openTab("一级库位管理", url);
    }*/

    $('#btnRefresh').click(function() {
        $('#bootstrap-table-first').bootstrapTable('refresh');
    });

    function removeStore(id) {
        $.modal.confirm("确定删除该条信息吗？", function() {
            debugger;
            var url =prefix + "/remove/"+id;
            $.operate.submit(url, "get", "json",function () {
                $("#bootstrap-table").bootstrapTable('refresh');
            });
        });
    }

    function refreshStore() {
        $("#bootstrap-table-first").bootstrapTable('refresh');
    }

</script>
</body>
</html>